package com.quasar.hpatient.presenter;
import com.quasar.hpatient.MainAppliaction;
import com.quasar.hpatient.constant.ConstantManger;
import com.quasar.hpatient.model.httpmodel.DataStateResult;
import com.quasar.hpatient.model.litePalmodel.TestCachedb;
import com.quasar.hpatient.model.medicalmodel.PatientInfoData;
import com.quasar.hpatient.model.requestmodel.RequestModel;
import com.quasar.hpatient.onInterface.AnotherResultListener;
import com.quasar.hpatient.utils.TimeZoneUtil;
import com.quasar.hpatient.view.viewInterface.ViewAnotherResultListener;

import java.util.Date;

/**
 * author : 许建宏
 * Date: 2017/11/8 0008
 * View:删除检查单item
 */

public class DeleteGetRecentDiagnosePresenter {

    PatientInfoData patientInfoData= MainAppliaction.getInstance().getPatient();
    private RequestModel requestModel;
    private ViewAnotherResultListener viewAnotherResultListener;

    public DeleteGetRecentDiagnosePresenter(ViewAnotherResultListener viewAnotherResultListener) {
        this.requestModel = new RequestModel();
        this.viewAnotherResultListener = viewAnotherResultListener;
    }

    /**
     * 删除item
     * @param id
     */
    public void DeleteGetRecentDiagnoseData(String id){

        requestModel.GetRecentDiagnoseData(id, new AnotherResultListener<DataStateResult>() {
            @Override
            public void onSuccess(DataStateResult data) {
                viewAnotherResultListener.onViewListenerSuccess(data);
            }

            @Override
            public void onError(String msg) {
                viewAnotherResultListener.onViewListenerError(msg);
            }

            @Override
            public void onRefreshUI() {
                viewAnotherResultListener.onViewListenerRefreshUI();
            }
        });
    }


    /**
     * 提交化验单
     * @param list
     * @param checkTime
     * @param cover
     * @param statusVal
     */
    public void PostRemindMedicine(final String list, final String checkTime, String cover, int statusVal, final String doctorId){

        requestModel.SubmitTestRecord(list, checkTime, cover,statusVal,doctorId, new AnotherResultListener<DataStateResult>() {
            @Override
            public void onSuccess(DataStateResult data) {
                TestCachedb testCachedb=new TestCachedb();
                testCachedb.setPatientId(patientInfoData.getId());
                testCachedb.setContent(list);
                testCachedb.setTestDateTime(checkTime.substring(0,checkTime.length()-9));
                testCachedb.setType(ConstantManger.TESTVAL);
                testCachedb.setVersion(0);
                testCachedb.setUpdateDateTime(TimeZoneUtil.sdfFormat.format(new Date()));
                testCachedb.setDoctorId("-1");
                testCachedb.save();

                viewAnotherResultListener.onViewTestRecordSuccess(data);
            }

            @Override
            public void onError(String msg) {
                viewAnotherResultListener.onViewListenerError(msg);
            }

            @Override
            public void onRefreshUI() {
                viewAnotherResultListener.onViewListenerRefreshUI();
            }
        });

    }

}
